<?php

function amber_get_message($id) {
    $sql = '
    SELECT `m`.`id`,
    	   `m`.`parent_id`,
    	   `m`.`full_path`,
           `m`.`created`,
           `m`.`updated`,
           `m`.`expire`,
    	   `m`.`message`,
    	   `m`.`worldkey` is NOT NULL AS `secresp`,
    	   `m`.`options` & ' . AMBER_OPT_CRYPT . ' AS `secstorage`,
    	   `u`.`nickname`,
           EXISTS (
                   SELECT *
                     FROM `amber_messages` AS `m2`
                    WHERE `m2`.`parent_id` = `m`.`id`
                      AND `expire` > :expire
                  ) AS `nested`
      FROM `amber_messages` AS `m`,
      	   `amber_users`    AS `u`
     WHERE `m`.`id` = :id
       AND `m`.`expire` > :expire
       AND `u`.`id` = `m`.`user_id`
  ORDER BY `created`, `id`
    ';

    return array('resp' => amber_run_query($sql, array(':id' => $id, ':expire'=>microtime(TRUE))));
}

?>